package demo.screens
{
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.screens.Root;
	import com.urbansquall.ginger.Animation;
	import com.urbansquall.ginger.AnimationPlayer;
	import com.urbansquall.ginger.tools.AnimationBuilder;
	
	import demo.BitmapDataLibrary;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	public class BasicAnimationDemo extends DemoScreen
	{
		public function BasicAnimationDemo(a_parentScreen:IScreenItem=null)
		{
			super(a_parentScreen);
			
			screenLabel = "Basic Animation Example \n + \nAnimationBuilder";
			
			var bdLib:BitmapDataLibrary = new BitmapDataLibrary();
			var bd:BitmapData = bdLib.lookupBitmapData( BitmapDataLibrary.DOG_YELP_TS )
			
			// Create an animation manually
			var animation:Animation = new Animation( 12 );
			var rect:Rectangle = new Rectangle( 0, 0, 60, 40 );
			for( var i:int = 0; i < 4; i++ )
			{
				animation.addFrame( 1, bd, rect, -30, -20 );
				rect.x += 60;
			}
			animation.isLooping = true;
			
			m_dog = new AnimationPlayer();
			m_dog.addAnimation( "yelp", animation );
			m_dog.x = Root.WIDTH / 2;
			m_dog.y = Root.HEIGHT / 2 - m_dog.height;
			m_dog.scaleX = 2;
			m_dog.scaleY = 2;
			addChild( m_dog );
			
			// Create an animation using the AnimationBuilder class
			m_dog2 = new AnimationPlayer();
			animation = AnimationBuilder.importStrip( 12, bd, 60, 40, 4, 0, 0, 120, -30, -20 );
			animation.isLooping = true;
			m_dog2.addAnimation( "yelp", animation);
			
			m_dog2.x = 30;
			m_dog2.y = m_dog.y;
			addChild( m_dog2 );
		}
		
		public override function update(a_timePassed:int):void
		{
			m_dog.update( a_timePassed );
			
			m_dog2.rotation += 5;
			m_dog2.update( a_timePassed );
		}
		
		private var m_dog:AnimationPlayer;
		private var m_dog2:AnimationPlayer;
		
	}
}